1st question :

Timer1.Interval := 10000;
    SMsg := 'Please get up and relax your eyes';
    Timer1.Enabled := True;

After it counts, the pop-up screen will appear but after I click OK will the pop-up screen appear again?

2nd question :

procedure TForm1.Timer1Timer(Sender: TObject);
begin  
Timer1.Enabled := False;  
ShowMessage(SMsg); // <= But this is a popup-Window;
end;

For the code above, when I run the program, the pop-up screen will appear. But if I don't want any pop-up screen before I click the RUN button, what shpuld I do?

1-st answer :

Timer1.Interval := 10000;
    SMsg := 'Please get up and relax your eyes';
    Timer1.Enabled := True;

After it counts, the pop-up window will appear but after you click OK the pop-up window will not appear again, because inside the Timer1Timer procedure is a code:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;  // <= This prevents from another popup-window until Timer1 be activated again
  ShowMessage(SMsg);
end;

2-nd answer :

procedure TForm1.Timer1Timer(Sender: TObject);
begin  
Timer1.Enabled := False;  
ShowMessage(SMsg); // <= But this is a popup-Window;
end;

For the code above, when you run the program, the pop-up screen will appear BECAUSE YOU FORGOT YOUR Timer1's property Enabled True, but it must to be False, for not cause a popup-window at startup the program.

If I don't put this code in the TTimer procedure will it be alright?

procedure TForm1.Timer1Timer(Sender: TObject);
begin  
Timer1.Enabled := False;  
ShowMessage(SMsg); // <= But this is a popup-Window;
end;

If I don't put this code in the TTimer procedure will it be alright?

procedure TForm1.Timer1Timer(Sender: TObject);
begin  
  Timer1.Enabled := False;  
  ShowMessage(SMsg); // <= But this is a popup-Window;
end;

The above code is very important, so without the code inside the Timer1Timer procedure nothing will be allright:

procedure TForm1.Timer1Timer(Sender: TObject);
begin  
  Timer1.Enabled := False;  // <= Prevents from second appearing of popup-Window
  ShowMessage(SMsg);        // <= Shows the first popup-Window;
end;

The above code is very important, so without the code inside the Timer1Timer procedure nothing will be allright:

procedure TForm1.Timer1Timer(Sender: TObject);
begin  
  Timer1.Enabled := False;  // <= Prevents from second appearing of popup-Window
  ShowMessage(SMsg);        // <= Shows the first popup-Window;
end;

Ok. That means whenever I run the program this TTimer will pop-up first then when it detects the temperature, the second pop-up will appear is it?

Ok. That means whenever I run the program this TTimer will pop-up first then when it detects the temperature, the second pop-up will appear is it?

Whenever you run the program:
1. case - Property Enabled of the Timer1 is False - Timer1 is not active, no popup-Window. When your program executes the code:

SMsg := 'This is the first popup-Window';
Timer1.Interval := 5000;
Timer1.Enabled := True;

after 5 seconds you will see the popup-Message "This is the first popup-Window" ...
2. case - Property Enabled of the Timer1 is True - Timer1 is active, first popup-Window will appear Interval ms after the run. When your program executes the code:

SMsg := 'This is the popup-Window';
Timer1.Interval := 5000;
Timer1.Enabled := True;

after 5 seconds you will see another popup-Message "This is the popup-Window" ...

procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
  Str,temp, ZW_WAR: String;
  DateTime : TDateTime;
  b,Nodeadresse:byte;
  dbm, D751, HeatSink, HeatFlux,thot,tcold,DT,TEGV,Ubat,Pout,rssi,energybalance :double;
  a:byte;
  dummy:integer;
  letzte:longint;
  SMsg: String;
   begin
   Timer1.Enabled := False;
   Timer1.Interval := 10000;
    SMsg := 'Please get up and relax your eyes';
    showMessage(SMsg);
   Timer1.Enabled := True;
  //get actual data and store it in "str"
  ComPort.ReadStr(Str, Count);
  //store every char from str in "rawdata" until cr + lf
  for a := 1 to length(str) do begin
    inc(laenge);
    rawdata[laenge]:=ord(str[a]);
    if (rawdata[laenge]=10) and (rawdata[laenge-1]= 13)then begin
      // if received protocol have the defined length of 11 then it is the right one
      if laenge=11 then begin
         //give rawdate from "rawdata" to "rawdata2" and clear rawdata
         for dummy:=1 to 11 do begin rawdata2[dummy]:=rawdata[dummy];rawdata[dummy]:=0;end;
         edit6.Text:='';
         for dummy:= 1 to 11 do edit6.Text:=edit6.Text+inttostr(rawdata2[dummy])+' ';
         nodeadresse:=ord(rawdata2[1]);
         //check if the address of the actual TE-Power-NODE already exists or not
         if nodeadressen[1]=0 then begin nodeadressen[1]:=nodeadresse;pagecontrol1.Pages[0].Caption:='NODE '+inttostr(nodeadresse);end;
         node:=99;
         for dummy:=1 to nodeanzahl do
             if nodeadressen[dummy]=nodeadresse then node:=dummy;
             if node = 99 then if nodeanzahl<5 then begin
                inc(nodeanzahl);nodeadressen[nodeanzahl]:=nodeadresse;node:=nodeanzahl;
                pagecontrol1.Pages[nodeanzahl-1].Caption:='NODE '+inttostr(nodeadresse);pagecontrol1.Pages[nodeanzahl-1].TabVisible:=true;
             end;

I put all the code in red in this procedure. Will it works?

procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
  Str,temp, ZW_WAR: String;
  DateTime : TDateTime;
  b,Nodeadresse:byte;
  dbm, D751, HeatSink, HeatFlux,thot,tcold,DT,TEGV,Ubat,Pout,rssi,energybalance :double;
  a:byte;
  dummy:integer;
  letzte:longint;
  // SMsg: String; // This must to be declared globally
   begin
   Timer1.Enabled := False;
   Timer1.Interval := 10000;
   SMsg := 'Please get up and relax your eyes';
   Timer1.Enabled := True;
  //get actual data and store it in "str"
  ComPort.ReadStr(Str, Count);
  //store every char from str in "rawdata" until cr + lf
  for a := 1 to length(str) do begin
    inc(laenge);
    rawdata[laenge]:=ord(str[a]);
    if (rawdata[laenge]=10) and (rawdata[laenge-1]= 13)then begin
      // if received protocol have the defined length of 11 then it is the right one
      if laenge=11 then begin
         //give rawdate from "rawdata" to "rawdata2" and clear rawdata
         for dummy:=1 to 11 do begin rawdata2[dummy]:=rawdata[dummy];rawdata[dummy]:=0;end;
         edit6.Text:='';
         for dummy:= 1 to 11 do edit6.Text:=edit6.Text+inttostr(rawdata2[dummy])+' ';
         nodeadresse:=ord(rawdata2[1]);
         //check if the address of the actual TE-Power-NODE already exists or not
         if nodeadressen[1]=0 then begin nodeadressen[1]:=nodeadresse;pagecontrol1.Pages[0].Caption:='NODE '+inttostr(nodeadresse);end;
         node:=99;
         for dummy:=1 to nodeanzahl do
             if nodeadressen[dummy]=nodeadresse then node:=dummy;
             if node = 99 then if nodeanzahl<5 then begin
                inc(nodeanzahl);nodeadressen[nodeanzahl]:=nodeadresse;node:=nodeanzahl;
                pagecontrol1.Pages[nodeanzahl-1].Caption:='NODE '+inttostr(nodeadresse);pagecontrol1.Pages[nodeanzahl-1].TabVisible:=true;
             end;

It Will work after small changes ...

procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
  Str,temp, ZW_WAR: String;
  DateTime : TDateTime;
  b,Nodeadresse:byte;
  dbm, D751, HeatSink, HeatFlux,thot,tcold,DT,TEGV,Ubat,Pout,rssi,energybalance :double;
  a:byte;
  dummy:integer;
  letzte:longint;
  // SMsg: String; // This must to be declared globally
   begin
   Timer1.Enabled := False;
   Timer1.Interval := 10000;
   SMsg := 'Please get up and relax your eyes';
   Timer1.Enabled := True;
  //get actual data and store it in "str"
  ComPort.ReadStr(Str, Count);
  //store every char from str in "rawdata" until cr + lf
  for a := 1 to length(str) do begin
    inc(laenge);
    rawdata[laenge]:=ord(str[a]);
    if (rawdata[laenge]=10) and (rawdata[laenge-1]= 13)then begin
      // if received protocol have the defined length of 11 then it is the right one
      if laenge=11 then begin
         //give rawdate from "rawdata" to "rawdata2" and clear rawdata
         for dummy:=1 to 11 do begin rawdata2[dummy]:=rawdata[dummy];rawdata[dummy]:=0;end;
         edit6.Text:='';
         for dummy:= 1 to 11 do edit6.Text:=edit6.Text+inttostr(rawdata2[dummy])+' ';
         nodeadresse:=ord(rawdata2[1]);
         //check if the address of the actual TE-Power-NODE already exists or not
         if nodeadressen[1]=0 then begin nodeadressen[1]:=nodeadresse;pagecontrol1.Pages[0].Caption:='NODE '+inttostr(nodeadresse);end;
         node:=99;
         for dummy:=1 to nodeanzahl do
             if nodeadressen[dummy]=nodeadresse then node:=dummy;
             if node = 99 then if nodeanzahl<5 then begin
                inc(nodeanzahl);nodeadressen[nodeanzahl]:=nodeadresse;node:=nodeanzahl;
                pagecontrol1.Pages[nodeanzahl-1].Caption:='NODE '+inttostr(nodeadresse);pagecontrol1.Pages[nodeanzahl-1].TabVisible:=true;
             end;

It Will work after small changes ...

So it will works right? It will not go wrong even if I never put the code at the TTimer procedure right?

To works right you must to do:
1. Global declaration of SMsg: string;
2.

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  ShowMessage(SMsg);
end;

That means I still need to put this code

procedure TForm1.Timer1Timer(Sender: TObject);
begin  
Timer1.Enabled := False;  
ShowMessage(SMsg);
end;

at the TTimer procedure?

But when I press F9, the pop-up screen will appear. Now what I want is when I run the program, I don't want to see any pop-up screen to appear unless I click the RUN button on the GUI after I got some temperature reading then the pop-up screen will appear. How to do that?

You must to do :
At design time to set the Property of Timer1 Enabled to False;

and

for RUN button:

procedure TForm1.ButtonRUNClick(Sender: TObject);
begin
  SMsg := 'It was pressed the RUN button before 5 seconds';
  Timer1.Interval := 5000;
  Timer1.Enabled := True;
end;

You must to do :
At design time to set the Property of Timer1 Enabled to False;

and

for RUN button:

procedure TForm1.ButtonRUNClick(Sender: TObject);
begin
  SMsg := 'It was pressed the RUN button before 5 secons';
  Timer1.Interval := 5000;
  Timer1.Enabled := True;
end;

I try what can I do at home. If there's problem, I will approach you again. Thank you for your help.

procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
  Str,temp, ZW_WAR: String;
  DateTime : TDateTime;
  b,Nodeadresse:byte;
  dbm, D751, HeatSink, HeatFlux,thot,tcold,DT,TEGV,Ubat,Pout,rssi,energybalance :double;
  a:byte;
  dummy:integer;
  letzte:longint;
  // SMsg: String; // This must to be declared globally
   begin
   Timer1.Enabled := False;
   Timer1.Interval := 10000;
   SMsg := 'Please get up and relax your eyes';
   Timer1.Enabled := True;
  //get actual data and store it in "str"
  ComPort.ReadStr(Str, Count);
  //store every char from str in "rawdata" until cr + lf
  for a := 1 to length(str) do begin
    inc(laenge);
    rawdata[laenge]:=ord(str[a]);
    if (rawdata[laenge]=10) and (rawdata[laenge-1]= 13)then begin
      // if received protocol have the defined length of 11 then it is the right one
      if laenge=11 then begin
         //give rawdate from "rawdata" to "rawdata2" and clear rawdata
         for dummy:=1 to 11 do begin rawdata2[dummy]:=rawdata[dummy];rawdata[dummy]:=0;end;
         edit6.Text:='';
         for dummy:= 1 to 11 do edit6.Text:=edit6.Text+inttostr(rawdata2[dummy])+' ';
         nodeadresse:=ord(rawdata2[1]);
         //check if the address of the actual TE-Power-NODE already exists or not
         if nodeadressen[1]=0 then begin nodeadressen[1]:=nodeadresse;pagecontrol1.Pages[0].Caption:='NODE '+inttostr(nodeadresse);end;
         node:=99;
         for dummy:=1 to nodeanzahl do
             if nodeadressen[dummy]=nodeadresse then node:=dummy;
             if node = 99 then if nodeanzahl<5 then begin
                inc(nodeanzahl);nodeadressen[nodeanzahl]:=nodeadresse;node:=nodeanzahl;
                pagecontrol1.Pages[nodeanzahl-1].Caption:='NODE '+inttostr(nodeadresse);pagecontrol1.Pages[nodeanzahl-1].TabVisible:=true;
             end;

It Will work after small changes ...

How to declare globally?

// SMsg: String; // This must to be declared globally

Example 1 for global declaration of a variable:

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    ButtonRUN: TButton;
    procedure Timer1Timer(Sender: TObject);
    procedure ButtonRUNClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    SMsg:     string;
    procedure PopUpMsg(I: Integer;  S: string);
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

Example 2 for global declaration of a variable:

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    ButtonRUN: TButton;
    procedure Timer1Timer(Sender: TObject);
    procedure ButtonRUNClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  SMsg:  string;

implementation

{$R *.dfm}

I have these 2 codes in colour. I'm not sure is it working well or not? Can you analysis these codes for me? Thank you :)

procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
  Str,temp, ZW_WAR: String;
  DateTime : TDateTime;
  b,Nodeadresse:byte;
  dbm, D751, HeatSink, HeatFlux,thot,tcold,DT,TEGV,Ubat,Pout,rssi,energybalance :double;
  a:byte;
  dummy:integer;
  letzte:longint;
  i: Integer;
begin
   Timer1.Interval := 60000;
   i:=1;
   Timer1.Enabled := True;

  //get actual data and store it in "str"
  ComPort.ReadStr(Str, Count);
  //store every char from str in "rawdata" until cr + lf
  for a := 1 to length(str) do begin
    inc(laenge);
    rawdata[laenge]:=ord(str[a]);
    if (rawdata[laenge]=10) and (rawdata[laenge-1]= 13)then begin
      // if received protocol have the defined length of 11 then it is the right one
      if laenge=11 then begin
         //give rawdate from "rawdata" to "rawdata2" and clear rawdata
         for dummy:=1 to 11 do begin rawdata2[dummy]:=rawdata[dummy];rawdata[dummy]:=0;end;
         edit6.Text:='';
         for dummy:= 1 to 11 do edit6.Text:=edit6.Text+inttostr(rawdata2[dummy])+' ';
         nodeadresse:=ord(rawdata2[1]);
         //check if the address of the actual TE-Power-NODE already exists or not
         if nodeadressen[1]=0 then begin nodeadressen[1]:=nodeadresse;pagecontrol1.Pages[0].Caption:='NODE '+inttostr(nodeadresse);end;
         node:=99;
         for dummy:=1 to nodeanzahl do
             if nodeadressen[dummy]=nodeadresse then node:=dummy;
             if node = 99 then if nodeanzahl<5 then begin
                inc(nodeanzahl);nodeadressen[nodeanzahl]:=nodeadresse;node:=nodeanzahl;
                pagecontrol1.Pages[nodeanzahl-1].Caption:='NODE '+inttostr(nodeadresse);pagecontrol1.Pages[nodeanzahl-1].TabVisible:=true;
             end;
procedure TForm1.Timer1Timer(Sender: TObject);
var verbrauch,TEGenergy:real;
i: Integer;
begin
   if (i=5) then
   begin
    Timer1.Enabled := False;
    i:=0;
    ShowMessage('Please get up and relax your eyes');
   end;
    Inc(i);if form2.visible=false then checkbox5.Checked :=false;

if (now-ankunftnode1)<0.0001 then pagecontrol1.Pages[0].Highlighted:=true
  else pagecontrol1.Pages[0].Highlighted:=false;
if (now-ankunftnode2)<0.0001 then pagecontrol1.Pages[1].Highlighted:=true
  else pagecontrol1.Pages[1].Highlighted:=false;
if (now-ankunftnode3)<0.0001 then pagecontrol1.Pages[2].Highlighted:=true
  else pagecontrol1.Pages[2].Highlighted:=false;
if (now-ankunftnode4)<0.0001 then pagecontrol1.Pages[3].Highlighted:=true
  else pagecontrol1.Pages[3].Highlighted:=false;

if now-ankunft>0.0001 then
  begin
  edit2.Text:='0';
  edit3.Text:='0';
  edit5.Text:='0';
  edit7.Text:='0';
  edit9.Text:='0';
  edit10.Text:='0';
  edit11.Text:='0';
  label1.Visible:=false;
  label2.Visible:=false;
  label3.Visible:=false;
  label4.Visible:=false;
  image2.Visible:=false;
  progbar1.Visible:=false;
  end;
procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
Str,temp, ZW_WAR: String;
DateTime : TDateTime;
b,Nodeadresse:byte;
dbm, D751, HeatSink, HeatFlux,thot,tcold,DT,TEGV,Ubat,Pout,rssi,energybalance :double;
a:byte;
dummy:integer;
letzte:longint;
i: Integer;
begin
Timer1.Interval := 60000; // This causes Interval will be  = 60 secons after Enabling Timer1
Timer1.Enabled := True; // This Enables Timer1 and after 60 seconds will be executed the code in procedure Timer1Timer();



i:=1; // this is not related with the code in red
//get actual data and store it in "str"
ComPort.ReadStr(Str, Count);
//store every char from str in "rawdata" until cr + lf
for a := 1 to length(str) do begin
inc(laenge);
rawdata[laenge]:=ord(str[a]);
if (rawdata[laenge]=10) and (rawdata[laenge-1]= 13)then begin
// if received protocol have the defined length of 11 then it is the right one
if laenge=11 then begin
//give rawdate from "rawdata" to "rawdata2" and clear rawdata
for dummy:=1 to 11 do begin rawdata2[dummy]:=rawdata[dummy];rawdata[dummy]:=0;end;
edit6.Text:='';
for dummy:= 1 to 11 do edit6.Text:=edit6.Text+inttostr(rawdata2[dummy])+' ';
nodeadresse:=ord(rawdata2[1]);
//check if the address of the actual TE-Power-NODE already exists or not
if nodeadressen[1]=0 then begin nodeadressen[1]:=nodeadresse;pagecontrol1.Pages[0].Caption:='NODE '+inttostr(nodeadresse);end;
node:=99;
for dummy:=1 to nodeanzahl do
if nodeadressen[dummy]=nodeadresse then node:=dummy;
if node = 99 then if nodeanzahl<5 then begin
inc(nodeanzahl);nodeadressen[nodeanzahl]:=nodeadresse;node:=nodeanzahl;
pagecontrol1.Pages[nodeanzahl-1].Caption:='NODE '+inttostr(nodeadresse);pagecontrol1.Pages[nodeanzahl-1].TabVisible:=true;
end;



procedure TForm1.Timer1Timer(Sender: TObject);
var verbrauch,TEGenergy:real;
i: Integer;
begin
   if (i=5) then // not correct check because the variable i is not initialised and no body knows it's value
   begin
    Timer1.Enabled := False; // This Disables Timer1 ( if it is Enabled )
    i:=0; // initialization of i may be
    ShowMessage('Please get up and relax your eyes');
   end;
    Inc(i); // i := i + 1 := 0 + 1 := 1;  // no body needs this value

if form2.visible=false then checkbox5.Checked :=false;

if (now-ankunftnode1)<0.0001 then pagecontrol1.Pages[0].Highlighted:=true
  else pagecontrol1.Pages[0].Highlighted:=false;
if (now-ankunftnode2)<0.0001 then pagecontrol1.Pages[1].Highlighted:=true
  else pagecontrol1.Pages[1].Highlighted:=false;
if (now-ankunftnode3)<0.0001 then pagecontrol1.Pages[2].Highlighted:=true
  else pagecontrol1.Pages[2].Highlighted:=false;
if (now-ankunftnode4)<0.0001 then pagecontrol1.Pages[3].Highlighted:=true
  else pagecontrol1.Pages[3].Highlighted:=false;

if now-ankunft>0.0001 then
  begin
  edit2.Text:='0';
  edit3.Text:='0';
  edit5.Text:='0';
  edit7.Text:='0';
  edit9.Text:='0';
  edit10.Text:='0';
  edit11.Text:='0';
  label1.Visible:=false;
  label2.Visible:=false;
  label3.Visible:=false;
  label4.Visible:=false;
  image2.Visible:=false;
  progbar1.Visible:=false;
  end;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.